data in the BootStrap Framework [] Custom Attributes Understanding of Recommendations

  • 2021-07-21 06:52:04
  • OfStack

Thoughts on learning bootstrap in recent days, through data-api You can use all bootstrap plug-ins without writing 1 line of js code, which is much more convenient and is our preferred way.

Why are there so many plug-ins in bootstrap data-api Because we usually need to introduce bootstrap. css, bootstrap. js and jQuery. js when using bootstrap framework, and then we can use bootstrap framework with rich special effects without writing 1 point js code, because bootstrap. js has already helped us complete all js codes, which is completed through data-api, so data-api It is the core of js to complete special effects in the framework. It can be popularly understood as data-api It is a common attribute beginning with data. In js, we can pass this data-api Find an element.

jquery How to operate data-api:

Example


<div data-support = "pc"></div>
  <script>
  // Get support Value 
  console.log($('div').data('support'));
  // Settings support Value 
  $('div').data('support','mobile_divice');
  </script>

Method for operating data-api by native js:

Example


<div data-support = "pc" id = "support_device "></div>
  <script>
  var support = document.getElementsById("support_device");
  // Get support Value 

  console.log(support.dataset.support);
  // Settings support Value 
  support.dataset.support = "mobile_device";
    </script>

Writing documents for the first time, novice on the road, understanding may not be specific enough, perhaps some immature, please have the belly of the prime minister < . > . Native js and jQuery operation has a little gap, and now data-api browser compatibility is not perfect, but also greatly reduces the workload of developers, or worth recommending! If you have any questions, please leave me a message, and this site will reply to you in time. Thank you very much for your support to this site!


Related articles: